{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "1552f07b",
   "metadata": {
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "# 制作画中画的全景视频"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "718414a6",
   "metadata": {
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "<font style=\"font-size:20px;text-align:left;\" color=\"red\">\n",
    "    建议先观看：《制作全景视频》\n",
    "</font>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "34cc6558",
   "metadata": {
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "## 1、准备一张 CubeMap 6x1 全景图片"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c1bb6a0b",
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "from IPython.display import Image, Audio, Video\n",
    "from av_utils import show_img\n",
    "import os\n",
    "\n",
    "# CubeMap 6x1全景图片文件路径\n",
    "cubemap_6x1_img_file = \"images/客厅全景6x1.jpg\"\n",
    "\n",
    "print(\"CubeMap 6x1图片路径：\", os.path.abspath(cubemap_6x1_img_file))\n",
    "\n",
    "# CubeMap 6x1全景图片\n",
    "show_img(cubemap_6x1_img_file)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "883d36e0",
   "metadata": {
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "## 2、准备一个画中画的视频"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "20efe258",
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "# 画中画的视频文件路径\n",
    "input_mp4_file = 'video/少年_片段.mp4'  \n",
    "\n",
    "print(\"原始视频路径：\", os.path.abspath(input_mp4_file))\n",
    "\n",
    "# 画中画的视频\n",
    "Video(input_mp4_file, width=320, height=180, embed=True)   "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "05bbf75f",
   "metadata": {
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "## 3、制作 CubeMap 6x1 画中画全景视频"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "34026318",
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "from av_utils import picture_in_picture\n",
    "\n",
    "# 打开画笔，找到图片中电视屏幕的开始和结束位置\n",
    "pos_start = (6518, 168) \n",
    "pos_end = (7430, 675)\n",
    "\n",
    "# CubeMap 6x1 画中画全景视频文件路径\n",
    "cubemap_6x1_pip_mp4 = 'output/客厅全景6x1_pip.mp4'\n",
    "\n",
    "# 制作 CubeMap 6x1 画中画全景视频\n",
    "picture_in_picture(cubemap_6x1_img_file, input_mp4_file, pos_start, pos_end, cubemap_6x1_pip_mp4)\n",
    "\n",
    "# CubeMap 6x1 画中画全景视频\n",
    "Video(cubemap_6x1_pip_mp4, width=900, height=150, embed=True)   "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ad58e374",
   "metadata": {
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "## 4、制作画中画全景视频"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "fe4c1ad8",
   "metadata": {
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "outputs": [],
   "source": [
    "from av_utils import cubemap_6x1_to_panorama\n",
    "\n",
    "# 画中画全景视频文件路径\n",
    "output_panorama_mp4 = 'output/客厅全景_画中画.mp4'\n",
    "\n",
    "# CubeMap 6x1 画中画全景视频 转 画中画全景视频\n",
    "cubemap_6x1_to_panorama(cubemap_6x1_pip_mp4, output_panorama_mp4)\n",
    "\n",
    "# 画中画全景视频\n",
    "Video(output_panorama_mp4, width=600, height=300, embed=True)   "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "92507fac",
   "metadata": {
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "## 5、用支持全景的软件查看\n",
    "\n",
    "<font style=\"font-size:20px;\">比如：PotPlayer、utovr、GoPro VR Player、Insta360 Player</font>\n",
    "<br><br>\n",
    "<font style=\"font-size:20px;\" color=\"red\">请搜索关键字“cubemap 全景”，了解更多\n",
    "    </font>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1118b28d",
   "metadata": {
    "pycharm": {
     "name": "#%% md\n"
    }
   },
   "source": [
    "## 6、上传到您的视频空间\n",
    "\n",
    "<font style=\"font-size:20px;\">支持 VR 360 短视频平台有：抖音、快手、B站、720云等等</font>\n",
    "<div style=\"text-align:left;background-color:#eee;\">\n",
    "<table>\n",
    "    <tr><td style=\"background-color:white;\"><img src=\"images/douyin_logo.svg\"></td>\n",
    "        <td style=\"background-color:black;\"><img src=\"images/kuaishou_logo.svg\"></td>\n",
    "        <td style=\"background-color:white;\"><img src=\"images/bilili_logo.svg\"></td>\n",
    "        <td style=\"background-color:white;\"><img src=\"images/720yun.png\"></td>        \n",
    "    </tr>\n",
    "</table>\n",
    "</div>"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
